package com.geek.javase.ch16.work;

import java.util.concurrent.CyclicBarrier;

/*
 *@author wangpeng
 *2025/11/2
 *@description TODO
 */
// 需求：公司召集5名员工开会，等5名员工都到了，会议开始。
public class Work2 {
    public static void main(String[] args) {
        CyclicBarrier brier = new CyclicBarrier(5,()->{
            System.out.println("5名员工都到了，会议开始。");
        });
        for (int i = 0; i < 5; i++) {
            new Thread(()->{
                try {
                    brier.await();
                    System.out.println(Thread.currentThread().getName() + "到了");
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }, "员工" + i).start();
        }
    }
}
